package cn.tedu.smartos.seniorcourse.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.seniorcourse.pojo.dto.*;
import cn.tedu.smartos.seniorcourse.pojo.vo.CourseCategoryVO;
import cn.tedu.smartos.seniorcourse.pojo.vo.CourseLessonVO;
import cn.tedu.smartos.seniorcourse.pojo.vo.CourseVO;
import cn.tedu.smartos.seniorcourse.pojo.vo.LearningRecordVO;
import cn.tedu.smartos.seniorcourse.service.CourseService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "07.老年课程")
@Slf4j
@RestController
@RequestMapping("/api/v1/courses/")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @ApiOperation("获取所有课程列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("list")
    public JsonResult list(Integer categoryId,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【课程列表】的请求,参数{},{},{}",categoryId,pageNum,pageSize);
        PageInfo<CourseVO> courseList = courseService.list(categoryId,pageNum,pageSize);
        return JsonResult.ok(courseList);
    }
    @ApiOperation("课程详情")
    @ApiOperationSupport(order = 20)
    @GetMapping("detail")
    public JsonResult detail(Long courseId){
        log.debug("开始处理【课程详情】的请求,参数{}",courseId);
        CourseVO course = courseService.detail(courseId);
        return JsonResult.ok(course);
    }
    @ApiOperation("添加课程")
    @ApiOperationSupport(order = 30)
    @PostMapping("add")
    public JsonResult add(@RequestBody CourseAddParam courseAddParam){
        log.debug("开始处理【添加课程】的请求,参数{}",courseAddParam);
        courseService.add(courseAddParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除课程")
    @ApiOperationSupport(order = 40)
    @PostMapping("delete")
    public JsonResult delete(@RequestBody List<Long> courseIds){
        log.debug("开始处理【删除课程】的请求,参数{}",courseIds);
        courseService.delete(courseIds);
        return JsonResult.ok();
    }
    @ApiOperation("修改课程")
    @ApiOperationSupport(order = 50)
    @PostMapping("update")
    public JsonResult update(@RequestBody CourseUpdateParam courseUpdateParam){
        log.debug("开始处理【修改课程】的请求,参数{}",courseUpdateParam);
        courseService.update(courseUpdateParam);
        return JsonResult.ok();
    }

//————————————————————————————————————————————————————————————————————————————
    /**
     * 课程分类管理
     */
    @ApiOperation("课程分类列表")
    @ApiOperationSupport(order = 100)
    @GetMapping("category/list")
    public JsonResult categoryList(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "10") Integer pageSize) {
        log.debug("开始处理【课程分类列表】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<CourseCategoryVO> list = courseService.listCategory(pageNum, pageSize);
        return JsonResult.ok(list);
    }
    @ApiOperation("课程分类详情")
    @ApiOperationSupport(order = 110)
    @GetMapping("category/detail")
    public JsonResult categoryDetail(Long categoryId) {
        log.debug("开始处理【课程分类详情】的请求,参数{}",categoryId);
        CourseCategoryVO detail = courseService.detailCategory(categoryId);
        return JsonResult.ok(detail);
    }
    @ApiOperation("添加课程分类")
    @ApiOperationSupport(order = 120)
    @PostMapping("category/add")
    public JsonResult addCategory(@RequestBody CourseCategoryAddParam courseCategoryAddParam) {
        log.debug("开始处理【添加课程分类】的请求,参数{}",courseCategoryAddParam);
        courseService.addCategory(courseCategoryAddParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除课程分类")
    @ApiOperationSupport(order = 130)
    @PostMapping("category/delete")
    public JsonResult deleteCategory(@RequestBody List<Long> categoryIds) {
        log.debug("开始处理【删除课程分类】的请求,参数{}",categoryIds);
        courseService.deleteCategory(categoryIds);
        return JsonResult.ok();
    }

//——————————————————————————————————————————————————————————————————————————————————
    /**
     * 课程章节管理
     */

    @ApiOperation("课程章节列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("lesson/list")
    public JsonResult listLessons(@RequestParam Long courseId,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【课程章节列表】的请求,参数{},{},{}",courseId,pageNum,pageSize);
        PageInfo<CourseLessonVO> lessonList = courseService.listLessons(courseId,pageNum,pageSize);
        return JsonResult.ok(lessonList);
    }
    @ApiOperation("课程章节详情")
    @ApiOperationSupport(order = 210)
    @GetMapping("lesson/detail")
    public JsonResult detailLesson(Long lessonId){
        log.debug("开始处理【课程章节详情】的请求,参数{}",lessonId);
        CourseLessonVO lesson = courseService.detailLesson(lessonId);
        return JsonResult.ok(lesson);
    }
    @ApiOperation("添加课程章节")
    @ApiOperationSupport(order = 220)
    @PostMapping("lesson/add")
    public JsonResult addLesson(@RequestBody CourseLessonAddParam courseLessonAddParam){
        log.debug("开始处理【添加课程章节】的请求,参数{}",courseLessonAddParam);
        courseService.addLesson(courseLessonAddParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除课程章节")
    @ApiOperationSupport(order = 230)
    @PostMapping("lesson/delete")
    public JsonResult deleteLesson(@RequestBody List<Long> lessonIds){
        log.debug("开始处理【删除课程章节】的请求,参数{}",lessonIds);
        courseService.deleteLesson(lessonIds);
        return JsonResult.ok();
    }
    @ApiOperation("修改课程章节")
    @ApiOperationSupport(order = 240)
    @PostMapping("lesson/update")
    public JsonResult updateLesson(@RequestBody CourseLessonUpdateParam courseLessonUpdateParam){
        log.debug("开始处理【修改课程章节】的请求,参数{}",courseLessonUpdateParam);
        courseService.updateLesson(courseLessonUpdateParam);
        return JsonResult.ok();
    }

//————————————————————————————————————————————————————————————————————————————

    /**
     * 课程学习记录管理
     */

    @ApiOperation("添加学习记录")
    @ApiOperationSupport(order = 300)
    @PostMapping("record/add")
    public JsonResult addRecord(@RequestBody LearningRecordAddParam learningRecordAddParam){
        log.debug("开始处理【添加学习记录】的请求,参数{}",learningRecordAddParam);
        courseService.addRecord(learningRecordAddParam);
        return JsonResult.ok();
    }
    @ApiOperation("课程学习记录列表")
    @ApiOperationSupport(order = 310)
    @GetMapping("record/list")
    public JsonResult listRecords(@RequestParam Long elderlyUserId,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【课程学习记录列表】的请求,参数{},{},{}",elderlyUserId,pageNum,pageSize);
        PageInfo<LearningRecordVO> list = courseService.listRecords(elderlyUserId,pageNum,pageSize);
        return JsonResult.ok(list);
    }
    @ApiOperation("课程学习记录详情")
    @ApiOperationSupport(order = 310)
    @GetMapping("record/detail")
    public JsonResult detailRecord(Long recordId){
        log.debug("开始处理【课程学习记录详情】的请求,参数{}",recordId);
        LearningRecordVO learningRecordVO = courseService.detailRecord(recordId);
        return JsonResult.ok(learningRecordVO);
    }
    @ApiOperation("删除课程学习记录")
    @ApiOperationSupport(order = 320)
    @PostMapping("record/delete")
    public JsonResult deleteRecord(@RequestBody List<Long> recordIds){
        log.debug("开始处理【删除课程学习记录】的请求,参数{}",recordIds);
        courseService.deleteRecord(recordIds);
        return JsonResult.ok();
    }
}
